﻿/* =========================================
 * Description: Update Database
 * 
 * Functions:
 * -Account editing/updating for family member
 * 
 * -----------------------------------------
 * Date Finished: February 22, 2010
 * Author: Mark Dominic M. De Mesa
 *       : Krismagne M. Maximo
 * =========================================
 * */

/**
 * =========================================
 * Updated by: Monica DM. Tosino
 * Update(s): Graphical User Interface
 * Date Finished: March 1, 2010
 * =========================================
 * **/


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace SAHCPIMS
{
    public partial class UPDATE : Form
    {
        public string upName;

        public UPDATE()
        {
            InitializeComponent();
        }

        private void checkupButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show(upName);
            string searchString =
                 @"Provider=Microsoft.Jet.OLEDB.4.0;"
                + @"Data source=..\\SAHCPIMS_database.mdb";
            OleDbConnection conn = new OleDbConnection(searchString);
            DataSet ds = new DataSet();
            conn.Open();
            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Family", conn);
            adapter.Fill(ds);

            conn.Close();
            DataTable dt = ds.Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                if ((upName.ToLower() == (dr["LastName"].ToString().ToLower())))
                {
                    addressTxtbox.Text = dr["Address"].ToString();
                    bdaytextBox.Text = dr["Birthday"].ToString();
                    famNumberTextBox.Text = dr["FamilyNum"].ToString();
                    nameTextBox.Text = dr["FirstName"].ToString() + " " + dr["MiddleName"].ToString() + " " + dr["LastName"].ToString();
                }


            }

            updateButton.Visible = true;
        }

        private void vaccineButton_Click(object sender, EventArgs e)
        {
            int converted = int.Parse(upName);
            MessageBox.Show(converted.ToString());
            string searchString =
                 @"Provider=Microsoft.Jet.OLEDB.4.0;"
                + @"Data source=..\\SAHCPIMS_database.mdb";
            OleDbConnection conn = new OleDbConnection(searchString);
            DataSet ds = new DataSet();
            conn.Open();
            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Family", conn);
            adapter.Fill(ds);

            conn.Close();
            DataTable dt = ds.Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                if (converted == int.Parse((dr["FamilyNum"].ToString())))
                {


                    addressTxtbox.Text = dr["Address"].ToString();
                    bdaytextBox.Text = dr["Birthday"].ToString();
                    famNumberTextBox.Text = dr["FamilyNum"].ToString();
                    nameTextBox.Text = dr["FirstName"].ToString() + " " + dr["MiddleName"].ToString() + " " + dr["LastName"].ToString();
                }


            }
            updateButton.Visible = true;
        }

        private void logOutButton_Click(object sender, EventArgs e)
        {
            LOGIN logout = new LOGIN();
            logout.Visible = true;
            this.Visible = false;
        }

        private void updateButton_Click(object sender, EventArgs e)
        {

        }
    }
}
